package com.traffic.between.service;

import org.apache.log4j.Logger;

import com.dahanbank.eif.http.common.ResponseMsg;
import com.dahanbank.eif.http.utils.DaHanClientUtil;
import com.google.gson.Gson;
import com.traffic.between.config.BetweenProperties;


public class DhstServiceImpl {
	private static Logger logger = Logger.getLogger(DhstServiceImpl.class);
	public static DhstServiceImpl service = new DhstServiceImpl();

	private static String DHST_ORDER_URL = BetweenProperties.DHST_ORDER_URL;
	private static String DHST_ORDERSTATUS_URL = BetweenProperties.DHST_ORDERSTATUS_URL;
	private static String DHST_APPKEY = BetweenProperties.DHST_APPKEY;
	private static String DHST_SECURITYKEY = BetweenProperties.DHST_SECURITYKEY;

	public String order(String productId, String phoneNo, String cstmOrderNo) {
		logger.info("between- 大汉三通订购请求参数: params productId = " + productId + ", phoneNo = " + phoneNo
				+ ", cstmOrderNo = " + cstmOrderNo);

		ResponseMsg _respMsg21 = null;
		try {
			_respMsg21 = DaHanClientUtil.orderFlow(DHST_ORDER_URL, DHST_APPKEY, DHST_SECURITYKEY, phoneNo,
					Integer.valueOf(productId), "dhst", cstmOrderNo);

			logger.info(("between- 大汉三通流量订购请求时的响应数据是: " + new Gson().toJson(_respMsg21)));
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("between- 大汉三通流量订购请求时的响应异常: " + e);
		}
		return new Gson().toJson(_respMsg21);
	}

	public String orderStatus(String cstmOrderNo) {
		logger.info("between- 大汉三通订购状态请求参数 method = orderStatus, params cstmOrderNo = " + cstmOrderNo);
		String _respMsg22 = null;
		try {
			_respMsg22 = DaHanClientUtil.query(DHST_ORDERSTATUS_URL, DHST_APPKEY, DHST_SECURITYKEY, cstmOrderNo);
			logger.info(("between- 大汉三通流量订购状态请求时的响应数据是: " + new Gson().toJson(_respMsg22)));
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("between- 大汉三通流量订购状态请求时的响应异常: " + e);
		}
		// 查询结 查询结 果为[],表明 该订单 正在 处理
		return new Gson().toJson(_respMsg22);
	}
}